Date.prototype.format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};
function contains(arr, obj) {
    if (arr == undefined) {
        return false;
    }
    var i = arr.length;
    while (i--) {
        if (arr[i] === obj) {
            return true;
        }
    }
    return false;
}
//去除字符串头尾空格或指定字符
String.prototype.Trim = function (c) {
    if (c == null || c == "") {
        var str = this.replace(/^s*/, '');
        var rg = /s/;
        var i = str.length;
        while (rg.test(str.charAt(--i)));
        return str.slice(0, i + 1);
    }
    else {
        var rg = new RegExp("^" + c + "*");
        var str = this.replace(rg, '');
        rg = new RegExp(c);
        var i = str.length;
        while (rg.test(str.charAt(--i)));
        return str.slice(0, i + 1);
    }
}
//去除字符串头部空格或指定字符  
String.prototype.TrimStart = function (c) {
    if (c == null || c == "") {
        var str = this.replace(/^s*/, '');
        return str;
    }
    else {
        var rg = new RegExp("^" + c + "*");
        var str = this.replace(rg, '');
        return str;
    }
}

//去除字符串尾部空格或指定字符  
String.prototype.trimEnd = function (c) {
    if (c == null || c == "") {
        var str = this;
        var rg = /s/;
        var i = str.length;
        while (rg.test(str.charAt(--i)));
        return str.slice(0, i + 1);
    }
    else {
        var str = this;
        var rg = new RegExp(c);
        var i = str.length;
        while (rg.test(str.charAt(--i)));
        return str.slice(0, i + 1);
    }
}
function GetDay(starttime, endtime) {
    var diff = ((new Date(endtime)).getTime() - (new Date(starttime)).getTime()) / (24 * 60 * 60 * 1000);
    if (diff <= 0) {
        return 0;
    } else {
        var str = diff.toString();
        if (str.indexOf(".") != -1) {
            diff = str.split(".");
            diff = diff[0];
            return diff;
        } else {
            return diff;
        }
    }
}
function GetAnalysisWindowFiterTimes(valuetoid, type, event) {
    var ntime = new Date();
    if (type == 'd') {
        var dstart = ntime.format("MM/dd/yyyy");
        var dend = ntime.format("MM/dd/yyyy");
        $("#" + valuetoid).val(dstart + " - " + dend);
    } else if (type == 'w') {
        var wstart = new Date(ntime.getTime() + (24 * 60 * 60 * -6 * 1000)).format("MM/dd/yyyy");
        var wend = ntime.format("MM/dd/yyyy");
        $("#" + valuetoid).val(wstart + ' - ' + wend);
    } else if (type == 'm') {
        var mstart = new Date(ntime.getTime() + (24 * 60 * 60 * -30 * 1000)).format("MM/dd/yyyy");
        var mend = ntime.format("MM/dd/yyyy");
        $("#" + valuetoid).val(mstart + ' - ' + mend);
    } else if (typeof type == 'number') {
        var start = new Date(ntime.getTime() - (type * 60 * 1000)).format('MM/dd/yyyy');
        var end = ntime.format("MM/dd/yyyy");
        $("#" + valuetoid).val(start + ' - ' + end);
    }
    if (event)eval(event);
}

function GetTablePageContent(allcount, allpage, nowpage, time, pagecontentid) {
    var code = "<span>共<b>" + allcount + "</b>条 合计<b id='" + pagecontentid + "_AllPage'>" + allpage + "</b>页</span>";
    if (nowpage > 1) {
        code += '<a class="countpage" href="javascript:void(0);" data-gopage="1">首页</a> ';
        code += '<a class="countpage" href="javascript:void(0);" data-gopage="' + (nowpage - 1)+'">上一页</a> ';
    }
    if (nowpage > 2) {
        for (var j = 4; j > 0; j--) {
            if (nowpage - j >= 1) {
                code += '<a class="countpage" href="javascript:void(0);" data-gopage="' + (nowpage - j) + '">' + (nowpage - j) + '</a> ';
            }
        }
    } else if (nowpage === 2) {
        code += '<a class="countpage" href="javascript:void(0);" data-gopage="1">1</a> ';
    }
    code += '<a class="countpage active" href="javascript:void(0);" data-gopage="' + nowpage + '">' + nowpage + '</a> ';
    for (var i = nowpage + 1; i < nowpage + 5; i++) {
        if (i < allpage + 1)
            code += '<a class="countpage" href="javascript:void(0);" data-gopage="' + i + '">' + i + '</a> ';
    }

    if ((nowpage + 5) < allpage)
        code += '<a class="countpage" href="javascript:void(0);" data-gopage="' + (nowpage + 1) +'">...</a> ';
    if (nowpage < allpage)
        code += '<a class="countpage" href="javascript:void(0);" data-gopage="' + (nowpage + 1) + '">下一页</a>';

    if (nowpage !== allpage) {
        code += '<a class="countpage" href="javascript:void(0);" data-gopage="' + allpage+'">尾页</a>';
    }
    code += '<span style="margin-right: -8px;margin-left: 5px;">跳转：</span><input type ="text" id="' + pagecontentid + '_GoPage" data-time="' + time + '" class="countpage" href="javascript:void(0);" value="' + nowpage + '"/><button class="countpage jumppagebtn">跳转</button>';
    return code;
}

function SetChartRefreshImgStyle(obj) {
    if ($(obj).data("deg") == null) {
        $(obj).data("deg", "0");
    }
    var deg = $(obj).data("deg") * 1;
    deg += 360;
    if (deg > 99999) {
        deg = 0;
    }
    $(obj).data("deg", deg);
    $(obj).css({ "transform": "rotate(" + deg + "deg)" });
}